package com.huawei.appgallery.essentialapp.ui;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewStub;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.huawei.appgallery.essentialapp.api.EssentialAppDataBean;
import com.huawei.appgallery.essentialapp.api.EssentialAppDataBean.OneAppInfoBean;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.ui.framework.widget.ObservableScrollView;
import com.huawei.appmarket.service.exposure.bean.ExposureDetail;
import com.huawei.hmf.annotation.FragmentDefine;
import huawei.widget.HwButton;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import o.azb;
import o.bmt;
import o.bqb;
import o.bqg;
import o.bqi;
import o.bqj.h;
import o.bql;
import o.bqm;
import o.bqp;
import o.ccx;
import o.cdh;
import o.cea;
import o.cep;
import o.cgv;
import o.cip;
import o.ckv;
import o.dgm;
import o.dyf;
import o.dyg;
import o.CollectCheck;
import o.eqh;
import o.eqp;
import o.NetWorkUtil;
import o.MinimumFactory;

@FragmentDefine(alias = "EssentialAppFragment")
public class EssentialAppFragment extends Fragment implements bqm, com.huawei.appgallery.foundation.ui.framework.widget.ObservableScrollView.a {
    private bql ʹ;
    private List<OneAppInfoBean> ʻˊ = new ArrayList();
    private dyf ʻˋ = new dyf();
    private List<View> ʻᐝ = new ArrayList();
    private ObservableScrollView ʼ;
    private c ʼˊ = new c();
    private a ʼˋ = new a();
    private LinearLayout ʽ;
    private OnClickListener ʽˊ = new OnClickListener(this) {
        final /* synthetic */ EssentialAppFragment ˊ;

        {
            this.ˊ = r1;
        }

        public void onClick(View view) {
            this.ˊ.ˎ(view);
        }
    };
    private long ʽˋ = 0;
    private Timer ʾॱ = new Timer();
    private bqg ˋ;
    private View ˎ;
    boolean ˏ = false;
    private bqp ॱ = bqi.ʼ();
    private cip ॱॱ;
    private ViewStub ᐝ;
    private View ﹳ;
    private boolean ﾞ = false;
    private TextView ﾟ;

    class a {
        final /* synthetic */ EssentialAppFragment ˏ;

        private a(EssentialAppFragment essentialAppFragment) {
            this.ˏ = essentialAppFragment;
        }

        private void ˋ() {
            if (this.ˏ.ॱ != null) {
                Context ॱˊ = this.ˏ.ॱˊ();
                if (ॱˊ != null) {
                    CheckBox checkBox = (CheckBox) this.ˏ.ˎ.findViewById(d.ॱᐝ);
                    checkBox.setText(NetWorkUtil.getWifiResId(ॱˊ, h.ˊ));
                    if (this.ˏ.ॱ.ˏॱ() || !eqh.ˎ().ˏ() || !cep.ˏ() || cep.ॱ(false)) {
                        checkBox.setVisibility(8);
                        this.ˏ.ॱ.ॱ(0);
                        return;
                    }
                    if (2 == this.ˏ.ॱ.ॱॱ()) {
                        checkBox.setChecked(false);
                    } else {
                        this.ˏ.ॱ.ॱ(1);
                        checkBox.setChecked(true);
                    }
                    checkBox.setVisibility(0);
                    checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener(this) {
                        final /* synthetic */ a ˋ;

                        {
                            this.ˋ = r1;
                        }

                        public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
                            this.ˋ.ˏ.ॱ.ॱ(z ? 1 : 2);
                        }
                    });
                }
            }
        }

        private void ॱ() {
            if (this.ˏ.ॱ == null) {
                bqb.ˋ.ˋ("EssentialAppFragment", "initPushCheckbox  mSource = null");
            } else if (this.ˏ.ॱˊ() == null) {
                bqb.ˋ.ˋ("EssentialAppFragment", "initPushCheckbox  context = null");
            } else {
                CheckBox checkBox = (CheckBox) this.ˏ.ˎ.findViewById(d.ˏॱ);
                checkBox.setText(h.ʼ);
                checkBox.setVisibility(0);
                if (2 == this.ˏ.ॱ.ˊॱ()) {
                    this.ˏ.ॱ.ˋ(2);
                    checkBox.setChecked(false);
                } else {
                    this.ˏ.ॱ.ˋ(1);
                    checkBox.setChecked(true);
                }
                checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener(this) {
                    final /* synthetic */ a ˊ;

                    {
                        this.ˊ = r1;
                    }

                    public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
                        int i = z ? 1 : 2;
                        bqb.ˋ.ˋ("EssentialAppFragment", "initPushCheckbox  state = " + i);
                        this.ˊ.ˏ.ॱ.ˋ(i);
                    }
                });
            }
        }

        private void ˏ() {
            HwButton hwButton = (HwButton) this.ˏ.ˎ.findViewById(d.ˋॱ);
            if (hwButton != null) {
                hwButton.setText(this.ˏ.ˎ(h.ˋ, Integer.valueOf(this.ˏ.ʻˊ == null ? 0 : this.ˏ.ʻˊ.size())));
                if ((this.ˏ.ʻˊ == null ? 0 : this.ˏ.ʻˊ.size()) == 0) {
                    hwButton.setClickable(false);
                    hwButton.setAlpha(0.5f);
                    return;
                }
                hwButton.setAlpha(1.0f);
                hwButton.setClickable(true);
                hwButton.setOnClickListener(this.ˏ.ʽˊ);
            }
        }

        private void ˊ() {
            if (this.ˏ.ॱ != null) {
                EssentialAppDataBean ᐝ = this.ˏ.ॱ.ᐝ();
                int ˊ = ᐝ == null ? 0 : ᐝ.ˊ();
                Context ॱˊ = this.ˏ.ॱˊ();
                if (ॱˊ != null) {
                    try {
                        this.ˏ.ᐝ.inflate();
                    } catch (Exception e) {
                        this.ˏ.ᐝ.setVisibility(0);
                    }
                    this.ˏ.ʼᐝ();
                    this.ˏ.ʽˊ();
                    this.ˏ.ʼ = (ObservableScrollView) this.ˏ.ˎ.findViewById(d.ˏ);
                    this.ˏ.ʼ.setScrollStateListener(this.ˏ);
                    this.ˏ.ʽ = (LinearLayout) this.ˏ.ˎ.findViewById(d.ʻ);
                    TextView textView = (TextView) this.ˏ.ˎ.findViewById(d.ॱˎ);
                    int ˎ = this.ˏ.ʹ.ˎ();
                    int ˏ = this.ˏ.ʹ.ˏ();
                    this.ˏ.ʻᐝ.clear();
                    if (ˊ == 1) {
                        textView.setText(ᐝ.ॱॱ());
                        List ˋ = ᐝ.ˋ();
                        if (!CollectCheck.isEmpty(ˋ)) {
                            this.ˏ.ˊ(ॱˊ, ˋ, ˎ, ˏ);
                        }
                    } else if (ˊ == 2) {
                        View inflate;
                        textView.setText(ᐝ.ʽ());
                        List ˏ2 = ᐝ.ˏ();
                        if (!CollectCheck.isEmpty(ˏ2)) {
                            if (!TextUtils.isEmpty(ᐝ.ˏॱ())) {
                                inflate = LayoutInflater.from(ॱˊ).inflate(o.bqj.a.ˋ, null);
                                ((TextView) inflate.findViewById(d.ᐝॱ)).setText(ᐝ.ˏॱ());
                                this.ˏ.ʽ.addView(inflate);
                            }
                            if (ᐝ.ॱˊ() && !TextUtils.isEmpty(ᐝ.ˊॱ())) {
                                textView = (TextView) LayoutInflater.from(ॱˊ).inflate(o.bqj.a.ॱ, null);
                                textView.setText(ᐝ.ˊॱ());
                                LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -2);
                                layoutParams.bottomMargin = ॱˊ.getResources().getDimensionPixelSize(o.bqj.b.ˏ);
                                this.ˏ.ʽ.addView(textView, layoutParams);
                            }
                            this.ˏ.ˊ(ॱˊ, ˏ2, ˎ, ˏ);
                        }
                        ˏ2 = ᐝ.ˋ();
                        if (!CollectCheck.isEmpty(ˏ2)) {
                            if (!TextUtils.isEmpty(ᐝ.ͺ())) {
                                inflate = LayoutInflater.from(ॱˊ).inflate(o.bqj.a.ˋ, null);
                                ((TextView) inflate.findViewById(d.ᐝॱ)).setText(ᐝ.ͺ());
                                this.ˏ.ʽ.addView(inflate);
                            }
                            this.ˏ.ˊ(ॱˊ, ˏ2, ˎ, ˏ);
                        }
                    }
                    this.ˏ.ʼ.post(new Runnable(this) {
                        final /* synthetic */ a ˎ;

                        {
                            this.ˎ = r1;
                        }

                        public void run() {
                            this.ˎ.ˏ.ˈॱ();
                        }
                    });
                    if (VERSION.SDK_INT >= 16) {
                        this.ˏ.ʽ.announceForAccessibility(this.ˏ.ᐝॱ().getString(h.ˎ));
                    }
                    ˏ();
                }
            }
        }
    }

    class b {
        final /* synthetic */ EssentialAppFragment ˋ;

        private b(EssentialAppFragment essentialAppFragment) {
            this.ˋ = essentialAppFragment;
        }

        private void ˏ() {
            if (this.ˋ.ॱॱ == null) {
                this.ˋ.ॱॱ = new cip();
                this.ˋ.ॱॱ.ˎ(this.ˋ.ˎ.findViewById(d.ͺ));
                this.ˋ.ॱॱ.ˋ(new OnClickListener(this) {
                    final /* synthetic */ b ॱ;

                    {
                        this.ॱ = r1;
                    }

                    public void onClick(View view) {
                        this.ॱ.ˋ.ʼˊ.ˊ();
                    }
                });
            }
            this.ˋ.ॱॱ.ॱ(0);
        }

        private void ॱ() {
            if (this.ˋ.ॱॱ != null) {
                this.ˋ.ॱॱ.ॱ(8);
                this.ˋ.ॱॱ = null;
            }
            this.ˋ.ﾟ.setVisibility(8);
            this.ˋ.ﹳ.setVisibility(0);
        }
    }

    class c {
        final /* synthetic */ EssentialAppFragment ˋ;

        private c(EssentialAppFragment essentialAppFragment) {
            this.ˋ = essentialAppFragment;
        }

        private void ˊ() {
            if (this.ˋ.ˋ != null) {
                final Activity ॱˋ = this.ˋ.ॱˋ();
                final b bVar = new b();
                this.ˋ.ˋ.ˏ(ॱˋ, new o.bqg.b(this) {
                    final /* synthetic */ c ˊ;

                    public void ॱ() {
                        Activity ॱˋ = this.ˊ.ˋ.ॱˋ();
                        if (ॱˋ != null) {
                            ॱˋ.finish();
                        }
                    }

                    public void ˎ(EssentialAppDataBean essentialAppDataBean, int i) {
                        if (!this.ˊ.ˋ.ﾞ) {
                            bqb.ˋ.ˋ("EssentialAppFragment", "errorcode=" + i);
                            if (i == 0) {
                                if (this.ˊ.ˋ.ॱ != null) {
                                    this.ˊ.ˋ.ॱ.ˊ(essentialAppDataBean);
                                    this.ˊ.ˋ.ʻˊ = this.ˊ.ˋ.ॱ.ˋॱ();
                                    if (this.ˊ.ˋ.ॱ.ᐝ().ʻॱ()) {
                                        this.ˊ.ˋ.ʾॱ();
                                        return;
                                    }
                                    this.ˊ.ˋ.ʼˋ.ˊ();
                                }
                                bVar.ॱ();
                            } else if (ॱˋ != null && !ॱˋ.isFinishing()) {
                                this.ˊ.ˋ.ॱॱ.ˋ(ॱˋ.getString(h.ˏ), true, false);
                                this.ˊ.ˋ.ﾟ.setVisibility(8);
                                this.ˊ.ˋ.ﹳ.setVisibility(0);
                                this.ˊ.ˋ.ʼᐝ();
                                this.ˊ.ˋ.ʽˊ();
                            }
                        }
                    }
                });
                bVar.ˏ();
            }
        }
    }

    static class e {
        private final bqm ˋ;

        e(bqm o_bqm) {
            this.ˋ = o_bqm;
        }

        LinearLayout ˎ(Context context) {
            LinearLayout linearLayout = new LinearLayout(context);
            linearLayout.setOrientation(0);
            return linearLayout;
        }

        @TargetApi(16)
        View ˎ(Context context, int i, int i2, int i3, OneAppInfoBean oneAppInfoBean, int i4) {
            View inflate = LayoutInflater.from(context).inflate(i, null);
            LinearLayout linearLayout = (LinearLayout) inflate.findViewById(d.ʽ);
            linearLayout.setContentDescription(oneAppInfoBean.ʽ());
            ImageView imageView = (ImageView) inflate.findViewById(d.ˊ);
            imageView.setImportantForAccessibility(2);
            cea.ˎ(imageView, oneAppInfoBean.ˋॱ(), o.bqj.e.ˋ);
            CheckBox checkBox = (CheckBox) inflate.findViewById(d.ʼ);
            TextView textView = (TextView) inflate.findViewById(d.ˎ);
            textView.setImportantForAccessibility(2);
            textView.setText(oneAppInfoBean.ʽ());
            TextView textView2 = (TextView) inflate.findViewById(d.ॱ);
            textView2.setImportantForAccessibility(2);
            checkBox.setVisibility(0);
            textView2.setText(oneAppInfoBean.ᐝॱ());
            imageView.setAlpha(1.0f);
            ˋ(imageView, checkBox, oneAppInfoBean);
            textView.setAlpha(1.0f);
            if (this.ˋ.ˎ(oneAppInfoBean)) {
                checkBox.setChecked(true);
            } else {
                checkBox.setChecked(false);
            }
            if (oneAppInfoBean.ˊ() == 1) {
                inflate.findViewById(d.ॱˊ).setVisibility(0);
            }
            if ((i3 % i2 != 0 ? 1 : null) != null) {
                if (MinimumFactory.getBoolValue(context)) {
                    linearLayout.setPadding(0, 0, i4, 0);
                } else {
                    linearLayout.setPadding(i4, 0, 0, 0);
                }
            }
            return inflate;
        }

        private void ˋ(ImageView imageView, final CheckBox checkBox, final OneAppInfoBean oneAppInfoBean) {
            imageView.setOnClickListener(new OnClickListener(this) {
                final /* synthetic */ e ˏ;

                public void onClick(View view) {
                    this.ˏ.ˏ(checkBox, oneAppInfoBean);
                }
            });
            checkBox.setOnClickListener(new OnClickListener(this) {
                final /* synthetic */ e ˏ;

                public void onClick(View view) {
                    this.ˏ.ˏ(checkBox, oneAppInfoBean);
                }
            });
        }

        private void ˏ(CheckBox checkBox, OneAppInfoBean oneAppInfoBean) {
            boolean z = true;
            if (this.ˋ != null) {
                boolean z2;
                boolean ˎ = this.ˋ.ˎ(oneAppInfoBean);
                if (ˎ) {
                    z2 = false;
                } else {
                    z2 = true;
                }
                checkBox.setChecked(z2);
                bqm o_bqm = this.ˋ;
                if (ˎ) {
                    z = false;
                }
                o_bqm.ॱ(oneAppInfoBean, z);
            }
        }
    }

    public EssentialAppFragment() {
        AnonymousClass1 anonymousClass1 = null;
        this.ˋ = this.ॱ != null ? this.ॱ.ͺ() : null;
        if (this.ॱ != null) {
            anonymousClass1 = this.ॱ.ˋॱ();
        }
        if (anonymousClass1 != null) {
            this.ʻˊ = this.ॱ.ˋॱ();
        }
    }

    @Nullable
    public View ˋ(@NonNull LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
        this.ˎ = layoutInflater.inflate(this.ʹ.ˋ(), viewGroup, false);
        this.ﹳ = this.ˎ.findViewById(d.ˋ);
        this.ﾟ = (TextView) this.ˎ.findViewById(d.ˊॱ);
        if (this.ˏ) {
            this.ﾟ.setText(dgm.ॱ(5));
        }
        azb.ˏ(this.ﹳ);
        this.ᐝ = (ViewStub) this.ˎ.findViewById(d.ॱॱ);
        EssentialAppDataBean essentialAppDataBean = null;
        if (this.ॱ != null) {
            this.ॱ.ॱˊ();
            essentialAppDataBean = this.ॱ.ᐝ();
        }
        this.ʼˋ.ˏ();
        ॱ();
        if (essentialAppDataBean == null || essentialAppDataBean.ʻॱ()) {
            this.ʼˊ.ˊ();
        } else {
            this.ﹳ.setVisibility(0);
            this.ʼˋ.ˊ();
        }
        return this.ˎ;
    }

    public void ˏ(Bundle bundle) {
        super.ˏ(bundle);
        Context ॱˋ = ॱˋ();
        if (ॱˋ != null) {
            cgv.ˋ(ॱˋ, o.bqj.c.ˎ, o.bqj.c.ˎ);
            this.ˏ = cdh.ˎ(ॱˋ) == 5;
        }
        this.ʹ = bql.ॱ(ॱˋ, this.ˏ);
    }

    public void ˌ() {
        super.ˌ();
        if (this.ˋ != null) {
            this.ˋ.ॱ(ॱˊ());
        }
    }

    public void ˋᐝ() {
        super.ˋᐝ();
        if (this.ˋ != null) {
            this.ˋ.ˊ(ॱˊ());
        }
    }

    public void ˎˎ() {
        super.ˎˎ();
        this.ﾞ = true;
        if (this.ॱ != null) {
            bqb.ˋ.ˋ("EssentialAppFragment", "setOpenPreUpdate " + this.ॱ.ॱॱ());
        }
    }

    public void ᐝ() {
        super.ᐝ();
    }

    public void ॱ(OneAppInfoBean oneAppInfoBean, boolean z) {
        if (z) {
            oneAppInfoBean.ॱ(true);
            this.ʻˊ.add(oneAppInfoBean);
        } else {
            oneAppInfoBean.ॱ(false);
            this.ʻˊ.remove(oneAppInfoBean);
        }
        this.ʼˋ.ˏ();
    }

    public boolean ˎ(OneAppInfoBean oneAppInfoBean) {
        return oneAppInfoBean == null ? false : oneAppInfoBean.ॱ();
    }

    private void ॱ() {
        ((HwButton) this.ˎ.findViewById(d.ᐝ)).setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ EssentialAppFragment ˏ;

            {
                this.ˏ = r1;
            }

            public void onClick(View view) {
                this.ˏ.ʾॱ();
            }
        });
    }

    private void ʽˊ() {
        if (eqp.ᐝ() && !UserSession.getInstance().isLoginSuccessful() && ccx.ˎ()) {
            this.ʼˋ.ॱ();
            return;
        }
        bqb.ˋ.ˋ("EssentialAppFragment", "not initPushCheckbox");
        if (this.ॱ != null) {
            this.ॱ.ˋ(0);
        }
    }

    private void ʼᐝ() {
        if (!this.ˏ) {
            this.ʼˋ.ˋ();
        }
    }

    private void ʾॱ() {
        if (this.ˋ != null) {
            this.ˋ.ˏ(ॱˊ());
        }
    }

    private void ˊ(Context context, List<OneAppInfoBean> list, int i, int i2) {
        int i3 = 0;
        int size = list == null ? 0 : list.size();
        View view = null;
        e eVar = new e(this);
        int ˊ = this.ʹ.ˊ();
        int i4 = 0;
        while (i4 < size) {
            if (i4 % i == 0) {
                view = eVar.ˎ(context);
                LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -2);
                i3++;
                if (i3 * i >= size) {
                    layoutParams.bottomMargin = context.getResources().getDimensionPixelSize(o.bqj.b.ˏ);
                } else {
                    layoutParams.bottomMargin = context.getResources().getDimensionPixelSize(o.bqj.b.ˎ);
                }
                this.ʽ.addView(view, layoutParams);
            }
            int i5 = i3;
            View view2 = view;
            OneAppInfoBean oneAppInfoBean = (OneAppInfoBean) list.get(i4);
            View ˎ = eVar.ˎ(context, ˊ, i, i4, oneAppInfoBean, i2);
            if (view2 != null) {
                ˎ.setTag(oneAppInfoBean);
                this.ʻᐝ.add(ˎ);
                view2.addView(ˎ);
            }
            i4++;
            i3 = i5;
            view = view2;
        }
    }

    private void ˎ(View view) {
        if (!bmt.ˊ(ॱˊ())) {
            ckv.ˎ(ᐝॱ().getString(h.ॱॱ), 0);
        } else if (this.ˋ != null) {
            this.ˋ.ˏ(ॱˋ(), view, this.ʻˊ);
        }
    }

    public void ˋ(ObservableScrollView observableScrollView, int i) {
        if (i == 0) {
            ˈॱ();
        }
    }

    private void ˋ(List<OneAppInfoBean> list) {
        int ˎ = dgm.ˎ(ॱˋ());
        dyg ॱ = dyg.ॱ();
        for (OneAppInfoBean ॱˊ : list) {
            ExposureDetail ˎ2 = ExposureDetail.ˎ(ॱˊ.ॱˊ());
            if (ˎ2 != null) {
                ˎ2.ˊ("essential app");
                ॱ.ˎ(ˎ2, ˎ);
            }
        }
        this.ʻˋ.ˊ(ॱ, ˎ);
    }

    private long ʽᐝ() {
        return this.ʽˋ;
    }

    private void ˈॱ() {
        this.ʽˋ = System.currentTimeMillis();
        this.ʾॱ.schedule(new TimerTask(this) {
            final /* synthetic */ EssentialAppFragment ˋ;

            {
                this.ˋ = r1;
            }

            public void run() {
                if (System.currentTimeMillis() - this.ˋ.ʽᐝ() >= 1000) {
                    this.ˋ.ˉॱ();
                }
            }
        }, 1000);
    }

    private void ˉॱ() {
        List arrayList = new ArrayList();
        for (View view : this.ʻᐝ) {
            if (this.ʻˋ.ˎ(view) && (view.getTag() instanceof OneAppInfoBean)) {
                arrayList.add((OneAppInfoBean) view.getTag());
            }
        }
        ˋ(arrayList);
    }
}
